package plus.xj17520.org.controller;

import plus.xj17520.basic.domain.AjaxResult;
import plus.xj17520.basic.domain.BaseQuery;
import plus.xj17520.basic.util.PageList;
import plus.xj17520.org.domain.Employee;
import plus.xj17520.org.service.IEmployeeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

//Controller + ResponseBody
@RestController
@RequestMapping("empl")
/**
 * @Api 作用在类上 value 里面填写的是当前类的文档描述
 */
//alt + 键盘的左右键回到上一步或者下一步
//alt+ctrl+ 键盘的左右键去下一个table或者上一个table
@Api(value = "员工管理的接口文档",description = "员工管理的接口文档")
public class EmplController {
    @Autowired
    IEmployeeService employeeService;

    //查询所有

    /**
     * 1.url="/empl/findall"
     * 2.请求方式: get
     * 3.参数: 空参
     * 4.响应参数: list
     */
    @GetMapping("findall")
    public List<Employee> findAll(){
        return employeeService.findAll();
    }



    /**
     * 分页查询
     * @return
     */
    @PostMapping("findPage")
    public PageList<Employee> findPage(@RequestBody BaseQuery baseQuery){
        return employeeService.findPage(baseQuery,"username");
    }

    /**
     * 新增
     * @return
     */
    @PostMapping("add")
    public AjaxResult add(@RequestBody @Validated Employee employee){
         employeeService.insert(employee);
         return AjaxResult.me();
    }

}
